package com.nuoniu.sibanyun.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auther 小啊刚
 * @date 2021-01-07
 */
public class ResponseUtil {
    //发送内容
    public static void render(HttpServletResponse response, String contentType, String text) {
        response.setContentType(contentType);
        try {
            response.setHeader("X-Frame-Options", "SAMEORIGIN");
            response.getWriter().write(text);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //发送json
    public static void renderJson(HttpServletResponse response, String text) {
        response.setHeader("X-Frame-Options", "SAMEORIGIN");
        render(response, "application/json;charset=utf-8", text);
    }

    //发送xml
    public static void renderXml(HttpServletResponse response, String text) {
        render(response, "text/xml;charset=utf-8", text);
    }

    //发送text
    public static void renderText(HttpServletResponse response, String text) {
        render(response, "text/plain;charset=utf-8", text);
    }
}
